<template>
	<view class="cart-container" v-if="cart.length !== 0">
    <!-- 收货地址 -->
    <my-address></my-address>
    
    <!-- 购物车标题 -->
		<view class="cart-title">
      <uni-icons type="shop" size="18"></uni-icons>
      <text class="title-text">购物车</text>
    </view>
    <!-- 购物车列表 -->
    <uni-swipe-action>
      <block v-for="(item,index) in cart" :key="index">
      <uni-swipe-action-item :right-options="options" @click="swipeItemClick(item)">
              <my-goods :item="item" showRadio showNumBox @radio-changed="handleRadioChange" @numberbox-changed="handlenumberboxChange" ></my-goods>
      </uni-swipe-action-item>
      </block>
    </uni-swipe-action>
    <!-- 结算区域 -->
    <my-settle></my-settle>
	</view>
  <view class="emty-container" v-else>
    <image src="/static/cart_empty@2x.png" class="empty-image"></image>
    <text class="empty-text">这里空空如也~</text>
  </view>
</template>

<script>
  import badgeMix from '../../mixins/tabbar-badge.js'
  import myGoods from '../../components/my-goods.vue'
  import myAddress from '../../components/my-address.vue'
  import mySettle from '../../components/my-settle.vue'
  import { mapState, mapMutations } from 'vuex'
	export default {
    mixins:[badgeMix],
    
    components:{
      myGoods,
      myAddress,
      mySettle
    },
    
    computed:{
      ...mapState('m_cart',['cart'])
    },
		data() {
			return {
				options:[{
          text:'删除',
          style:{
            backgroundColor:'#C00000'
          }
        }]
			};
		},
    
    methods:{
      ...mapMutations('m_cart',['updateGoodsState','updateGoodsCount','removeGoodsById']),
      
      //处理商品radio勾选状态
      handleRadioChange(e){
        this.updateGoodsState(e)
      },
      
      //拿到numberBox最新对象（值）
      handlenumberboxChange(goods){
        this.updateGoodsCount(goods)
      },
      
      //处理左划删除按钮
      swipeItemClick(goods){
        this.removeGoodsById(goods)
      },
      
      
    }
	}
</script>

<style lang="scss">
  .cart-container{
    padding-bottom:50px;
  }
.cart-title{
  height: 40px;
  display: flex;
  align-items: center;
  padding-left: 5px;
  border-bottom: 1px solid #efefef;
    
  .title-text{
    font-size:14px;
    margin-left: 10px;
  }
  
}

.emty-container{
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top:150px;
  
  .empty-image{
    width:90px;
    height:90px;
  }
  
  .empty-text{
    font-size:14px;
    color:gray;
    margin-top:15px;
  }
}
</style>
